<?php

if (sizeof($arr_single_record)>0){
	$v_record_id = $arr_single_record['PK_RECORD'];
}else{
	$v_record_id = 0;
}
if(isset($_REQUEST['hdn_record_id'])){
	$v_record_id = intval($_REQUEST['hdn_record_id']);
}
$v_status = 1;
$v_filter = "";
$v_cate_id= 0;
if(_is_sqlserver()){
	$sql = "Exec Onegate_RecordWorkGetAll_DatCQ_170908 ";
	$sql = $sql ."'". $v_record_id."'" ;
	//echo $sql.'<br>';
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$arr_record_work = $ado_conn->GetAll($sql);	
	$v_count_record_work = sizeof($arr_record_work);	
	
	//DatCQ: Ngay hen tra ket qua cua ho so
	$sql = "select C_APPOINTED_DATE, C_RECEIVED_DATE,C_CURRENT_STATUS from T_ONEGATE_RECORD where PK_RECORD like '".$v_record_id."' ";
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$arr_appointed_date = $ado_conn->GetRow($sql);
	$v_date_appointed = $arr_appointed_date['C_APPOINTED_DATE'];
	$v_date_received = $arr_appointed_date['C_RECEIVED_DATE'];
	$v_current_status = $arr_appointed_date['C_CURRENT_STATUS'];
	
	if ($v_count_record_work>0){
		//bo thoi gian tiep nhan
		for($row_index = 1;$row_index< $v_count_record_work ;$row_index++)
		{
			if($arr_record_work[$row_index]['C_RECORD_STATUS']=='TU_CHOI' || $arr_record_work[$row_index]['C_RECORD_STATUS']=='CAP_PHEP' )
			{	
				$v_date_capphep = $arr_record_work[$row_index]['C_DATE'];
																	
		   }//end if
		}//end for
	}	
	$sql = "select C_PROCESS_DATE from T_ONEGATE_RECORDTYPE where PK_RECORDTYPE like '".$arr_single_record['FK_RECORDTYPE']."' ";
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$arr = $ado_conn->GetRow($sql);	
	
	//-leav_03022009
	$v_number_process = intval($arr['C_PROCESS_DATE']);
	$date = (getdate());
	$current_day = $date['year'].'-'.$date['mon'].'-'.$date['mday'];
	
	$date = (getdate());
	$current_day = $date['year'].'-'.$date['mon'].'-'.$date['mday'];
	$v_day_not_work=count_day_not_work($v_date_received,$v_date_appointed);
	$v_number_day_for_process=datediff($v_date_received,$v_date_appointed)-$v_day_not_work;
	if($v_date_appointed==false){
		$v_number_day_for_process = intval($arr['C_PROCESS_DATE']);
	}

	
	/*
	if($v_number_process!=$v_number_day_for_process){
		$v_number_day_for_process=$v_number_day_for_process+1;
	}*/
	//-leav_03022009_end
	$v_sum_status_process = '';
	
	
if($v_current_status <> 'TU_CHOI' || $v_current_status <> 'CAP_PHEP')
{
	
	// tinh so ngay da lam viec
	$v_number_day_processed = datediff($v_date_received,$current_day) - count_day_not_work($v_date_received,$current_day) ;//+ 1;
	//tinh so ngay lam viec cua cong viec phu thuoc vao cong dan 
	// ket thuc
	// tinh so ngay con lai
	$v_number_day_remain_process = $v_number_day_for_process - $v_number_day_processed;
	if ($v_number_day_remain_process < 0)
	{
		$v_number_day_remain_process = 0;
		$v_tre_hen = abs($v_number_day_for_process - $v_number_day_processed);
		$v_sum_status_process = '<font color="#FF0000">'.TRE_HEN_TD .$v_tre_hen. ' ng&agrave;y</font>';
	}
	else if ($v_number_day_remain_process == 0)
	{
		$v_sum_status_process = '<font color="#0000FF">'.TRA_KET_QUA_TD.'</font>';
	}
	else
	{
		$v_number_day_remain_process = $v_number_day_for_process - $v_number_day_processed;
		$v_sum_status_process = '<font color="#0000FF">'.DUNG_HEN_TD.'</font>';
		
	}
}
else
	{
	 

		$v_number_date_pheduyet = dateDiff($v_date_capphep,$v_date_appointed);
		
		$v_number_day_processed = datediff($v_date_received,$v_date_capphep) - count_day_not_work($v_date_received,$v_date_capphep) + 1;
		$v_number_day_remain_process = $v_number_day_for_process - $v_number_day_processed;
		
		if($v_number_date_pheduyet > 0)
		{
			$v_sum_status_process = '<font color="#0000FF">'.GQ_TRUOC_HEN_TD.'</font>';
		}
		else if($v_number_date_pheduyet = 0)
		{
			$v_sum_status_process = '<font color="#0000FF">'.GQ_DUNG_HEN_TD.'</font>';
			$v_number_day_remain_process = 0;
		}
		else
		{

			$v_sum_status_process = '<font color="#FF0000">'.GQ_TRE_HEN.'</font>';
			$v_number_day_remain_process = 0;
		}
	
	}		
}?>
